package com.wedimob.slideshare.parser.strategy;

import java.net.URI;

import org.jsoup.nodes.Document;

import com.wedimob.slideshare.WriteType;
import com.wedimob.slideshare.bo.Medium;
import com.wedimob.slideshare.bo.SharedDocument;
import com.wedimob.slideshare.bo.Summary;
import com.wedimob.slideshare.task.PoolExecutor;
import com.wedimob.slideshare.task.disk.PathHelper;
import com.wedimob.slideshare.task.network.TaskMediumWriter;

public class YoutubeDocumentParser implements ShareDocumentParser {

    private Summary summary;
    @SuppressWarnings("unused")
    private Document document;

    public YoutubeDocumentParser(Summary summary, Document document, WriteType write) {
        super();
        this.summary = summary;
        this.document = document;
    }

    @Override
    public SharedDocument get(PoolExecutor pool, WriteType write, int timeout) {

        URI mediumURI = PathHelper.buildTmpPath(summary.getAuthor(), summary.getTitle());
        Medium video = new Medium(summary.getTitle(), summary.getUrl(), mediumURI);
        
        if (write != WriteType.NONE)
            pool.execAsync(new TaskMediumWriter(pool, video, timeout));

        SharedDocument result = new SharedDocument(summary);
        result.addMedium(video);
        return result;
    }
}
